package com.ksl.kinglockguard.activity.base;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;

import com.ksl.kinglockguard.data.UserCountHabit;
import com.ksl.kinglockguard.network.ConnectChangeListener;
import com.ksl.kinglockguard.network.ConnectChangeListener.ConnectChangeListenerInterface;
import com.ksl.kinglockguard.utils.TaskStackUtil;
import com.lsk.open.core.MyLog;
import com.lsk.open.core.utils.ProductInfoUtils;

public abstract class AbstractActivity extends Activity implements ConnectChangeListenerInterface{

	protected long onResume = 0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		TaskStackUtil.pushStack(this.getClass().getSimpleName());
		MyLog.i("jyh", "~~~~~~~AbstractActivity onCreate    " + this.getClass().getSimpleName() + "    ~~~~~~");
		if(TaskStackUtil.isFirstActivityStart()){
			new Thread(new Runnable(){

				@Override
				public void run() {
					MyLog.e("ydy","first make UUID");
					ProductInfoUtils.getUUIDFromFile(AbstractActivity.this.getApplicationContext());//提前生成UUID
				}
				
			}).start();
		}
		super.onCreate(savedInstanceState);
		ConnectChangeListener.getInstance().setListener(this);
//		MobclickAgent.updateOnlineConfig( mContext );
	}

	@Override
	public void onConnectChange() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void onDestroy() {
		TaskStackUtil.pullStack(this.getClass().getSimpleName());
		TaskStackUtil.startKillThread(getApplicationContext());
		ConnectChangeListener.getInstance().remove(this);
		MyLog.i("wmm", "onDestroy");
		super.onDestroy();
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		onResume = System.currentTimeMillis();
		
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		int time = (int) (System.currentTimeMillis() - onResume);
		String key = getUserHabitKey();
		if(!TextUtils.isEmpty(key)){
			UserCountHabit.setUserCount(this, key,time+"");
		}
	}
	public abstract String getUserHabitKey();
	

}
